﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.NBL.DBEntities;
using lgweb.common;
using LGCourt.Logic.BLL;
using KMFrame.Permission.Util;
using LGCourt.Logic.Common;
using KMFrame.Core;

namespace lgweb.inside.intColumn
{
    public partial class index : NeedValidatePage
    {
        public string _DetpName = string.Empty;
        public string _DeptID = "0";
        public string _deptCode = string.Empty;
        public string _picUrl = string.Empty;
        string _cateName = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                this.hdOADomain.Value = System.Configuration.ConfigurationManager.AppSettings["OADomain"];
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "/lgmanage/Systems/upload/" : _picUrl;
                GetUserInfo();
                GetParam();
                GetNewsList();

            }
        }

        //获取个人信息
        private void GetUserInfo()
        {
            OA bll = new OA();
            vOAUser result = (vOAUser)bll.GetUserInfo(SessionBox.GetUserSession().UserID);

            if (result != null)
            {
               // this.topUsername.InnerHtml = result.realname;
            }
        }

        private void GetParam()
        {
            this._DeptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"].ToString();
            this._deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "ZZC" : Request.QueryString["Code"].ToString();
        }

        //获取资讯类信息列表
        private void GetNewsList()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();

            if (_DeptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(_deptCode);
                if (department != null)
                {                   
                    _DetpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = _DetpName;
            }
            else
            {
                param.ClassID = int.Parse(_DeptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            _DeptID = deptInfo.ID.ToString();
            _DetpName = deptInfo.Source;
            param = new DeptClassCondition();
            param.Name = "监察室栏目";
            List<V_DICT_SOURCE> classInfoList = colInfoBLL.GetDeptSourceList(param);

            //部门信息
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            if (deptIndex != null)
            {
                this.icodepttalg1.InnerHtml = deptIndex.StaffIndex;
                this.icodepttalg2.InnerHtml = deptIndex.FunctionsIndex; 
            }
            
            //部门动态    
            OA bll = new OA();   
            OANoticeCondition noticeParam = new OANoticeCondition();
            noticeParam.UserID = this.SessionInfo.UserID;
            noticeParam.DeptName = _DetpName;
            noticeParam.PageIndex = 1;
            noticeParam.PageSize = 9;
            PageResult result = (PageResult)bll.GetXinXiBaoSongPage(noticeParam);
            if (result != null && result.ResultList != null)
            {
                this.rptBMDTList.DataSource = (List<vOAXinXiBaoSong>)result.ResultList;
                this.rptBMDTList.DataBind();
            }
            this.aBMDTmore.HRef = string.Format("/inside/intColumn/notice.aspx?cate=1&classid={0}&deptid={1}", classInfoList.Count >= 1 ? classInfoList[0].ID.GetValueOrDefault(0) : 0, _DeptID);

            //工作动态     
            deptParam.PageSize = 9;
            deptParam.ClassID = classInfoList.Count >= 1 ? classInfoList[0].ID.GetValueOrDefault(0) : 1;
            this.hClassName2.InnerText = classInfoList.Count >= 1 ? classInfoList[0].Source: "工作动态";
            List<LGFY_Platform_Bmxx> gzdtList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (gzdtList != null)
            {
                this.rptGZDTList.DataSource = gzdtList;
                this.rptGZDTList.DataBind();
            }
            this.aGZDTmore.HRef = string.Format("/inside/intColumn/list.aspx?cate=2&classid={0}&deptid={1}", classInfoList.Count >= 1 ? classInfoList[0].ID.GetValueOrDefault(0) : 0, _DeptID);

            //廉政要闻     
            deptParam.PageSize = 9;
            deptParam.ClassID = classInfoList.Count >= 2 ? classInfoList[1].ID.GetValueOrDefault(0) : 2;
            this.hClassName3.InnerText = classInfoList.Count >= 2 ? classInfoList[1].Source : "廉政要闻";
            List<LGFY_Platform_Bmxx> lzywList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (lzywList != null)
            {
                this.rplLZYWList.DataSource = lzywList;
                this.rplLZYWList.DataBind();
            }
            this.aLZYWmore.HRef = string.Format("/inside/intColumn/list.aspx?cate=3&classid={0}&deptid={1}", classInfoList.Count >= 2 ? classInfoList[1].ID.GetValueOrDefault(0) : 0, _DeptID);

            //政策法规     
            deptParam.PageSize = 9;
            deptParam.ClassID = classInfoList.Count >= 3 ? classInfoList[2].ID.GetValueOrDefault(0) : 3;
            this.hClassName4.InnerText = classInfoList.Count >= 3 ? classInfoList[2].Source : "政策法规";
            List<LGFY_Platform_Bmxx> zcfgList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (zcfgList != null)
            {
                this.rplZCFGList.DataSource = zcfgList;
                this.rplZCFGList.DataBind();
            }
            this.aZCFGmore.HRef = string.Format("/inside/intColumn/list.aspx?cate=4&classid={0}&deptid={1}", classInfoList.Count >= 3 ? classInfoList[2].ID.GetValueOrDefault(0) : 0, _DeptID);

            //警钟长鸣     
            deptParam.PageSize = 9;
            deptParam.ClassID = classInfoList.Count >= 4 ? classInfoList[3].ID.GetValueOrDefault(0) : 4;
            this.hClassName5.InnerText = classInfoList.Count >= 4 ? classInfoList[3].Source : "警钟长鸣";
            List<LGFY_Platform_Bmxx> jzcmList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (jzcmList != null)
            {
                this.rptJZCMList.DataSource = jzcmList;
                this.rptJZCMList.DataBind();
            }
            this.aJZCMmore.HRef = string.Format("/inside/intColumn/list.aspx?cate=5&classid={0}&deptid={1}", classInfoList.Count >= 4 ? classInfoList[3].ID.GetValueOrDefault(0) : 0, _DeptID);


            //轮播图片
            deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            deptParam.PageSize = 6;
            deptParam.IsPicRoll = true;
            List<LGFY_Platform_Bmxx> LBList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (LBList != null)
            {
                this.rptlbList1.DataSource = LBList;
                this.rptlbList1.DataBind();

                this.rptlbList2.DataSource = LBList;
                this.rptlbList2.DataBind();
            }
        }
    }
}